/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketmaster.dao;

import ticketmaster.dataobject.Tax;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import java.util.logging.*;
/**
 *
 * @author Xiaolong Xue
 */
public class TaxDAO extends BaseEntityDAO
{
    public TaxDAO()
    {
        // construct a TaxDAO object
    }

    /**
     * Insert tax into database
     * @param tax the new tax entity to be inserted
     * @return newly created taxID or a 0 on error
     */
     public int insertTax(Tax tax)
     {
         return save(tax);
     }

    /**
     * Delete tax that matches the supplied criteria
     * @param tax the supplied criteria
     * @return true on success, false on failure
     */
     public boolean deleteTax(Tax tax)
     {
         return delete(tax);
     }

    /**
     * Update the tax using data from the tax Data Object
     * @param tax the tax Data Object to be updated
     * @return true on success, false on failure or error
     */
     public boolean updateTax(Tax tax)
     {
         if(tax.getTaxID() == 0)
             return false;
         return update(tax);
     }

    /**
     * Get the tax that matches the supplied criteria
     * @param tax the supplied criteria
     * @return a Tax Data Object if found, or null on error or if not found
     */
     public Tax findTax(Tax tax)
     {
         String sql = null;
         if(tax.getTaxID() == 0)
             return null;
         else
             sql = buildQuerySQL(tax);

         RowSet trs = query(sql);

         try
         {
             trs.next();
         }
         catch(SQLException ex)
         {
             Logger.getLogger(TaxDAO.class.getName()).log(Level.SEVERE, null, ex);
         }

         return (Tax) this.getObject(trs, tax);
     }

    /**
     * Get all taxes that match the supplied criteria
     * @param tax supplied criteria
     * @return a RowSet
     */
    public RowSet getTaxRowSet(Tax tax)
    {
        String sql = buildQuerySQL(tax);
        return query(sql);
    }

    /**
     * Get all taxes that match the supplied criteria
     * @param tax supplied criteria
     * @return a collection of Tax Data Objects
     */
    public Collection<Tax> getTaxDO(Tax tax)
    {
        String sql = buildQuerySQL(tax);
        RowSet trs = query(sql);
        Collection<Tax> taxes = new ArrayList<Tax>();

        try
        {
            while(trs.next())
            {
                Tax taxDO = (Tax) this.getObject(trs,tax);
                taxes.add(taxDO);
            }
        }
        catch(SQLException ex)
        {
            Logger.getLogger(TaxDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return taxes;
    }
}
